package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"jianghairui/uni-upload/appconfig"
	"jianghairui/uni-upload/middleware"
	"jianghairui/uni-upload/routers"
	"log"
)

func main() {
	appMode := appconfig.AppConfig.Section("").Key("app_mode").String()
	appPort := appconfig.AppConfig.Section("").Key("app_port").String()

	var r *gin.Engine
	if appMode == "production" {
		gin.SetMode(gin.ReleaseMode)
		// 设置全局日志中间件
		r = gin.New()
		r.Use(middleware.Cors())
		r.Use(middleware.LoggerToFile())
		r.Use(middleware.CustomRecovery())
	} else {
		r = gin.Default()
	}
	routers.GinConfigure(r)

	r.GET("/", func(context *gin.Context) {
		context.String(200, "You Know! For Upload")
	})
	// 路由分组
	routers.OssRouterInit(r)
	fmt.Printf("%-32s%-32s\n", "listen on "+appPort+":", "")
	err := r.Run(":" + appPort)
	if err != nil {
		log.Fatal(err.Error())
	}

}
